import { toMoney } from '../utils'
export default function (opt = {}) {
    // console.log(opt, 'opt');
    let color = ['#01458e', '#9ed7ea', '#6c5dd2', '#4d98eb', '#bcd3ff']
    let pieData = []
    if (opt.data && opt.data.length) {
        pieData = opt.data.map(item => {
            return {
                ...item,
                value: Math.abs(item.value)
            }
        })
    }
    console.log(pieData, 'data');
    return {
        tooltip: {
            trigger: 'item',
            formatter: (param) => {
                // console.log(param,'1111111~~');
                let val = 0
                opt.data.find(item => {
                    if (item.name == param.name) {
                        return val = item.value
                    }
                })
                return `${param.name} ${toMoney(Number(val) / 10000)} 万元`
            }
        },
        color,
        series: [
            {
                type: 'pie',
                radius: '50%',
                data: pieData || [],
                minAngle: 10,
                itemStyle: {
                    color: (params) => {
                        // console.log(params, 'color');
                        return color[params.dataIndex % 5]
                    }
                },
                emphasis: {
                    itemStyle: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    }
}